package org.spring.blog.controller.portal;


import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.spring.blog.response.ResponseResult;
import org.spring.blog.response.ResponseState;
import org.spring.blog.service.ISolrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/portal/search")
public class SearchPortalApi {

    @Autowired
    private ISolrService solrService;

    /**
     * 搜索接口
     *
     * @param keyword    关键词
     * @param page       页码
     * @param size       页面大小
     * @param categoryId 分类id
     * @param sort       排序方式
     * @return 自定义的返回类型
     */
    @ApiOperation("")
    @ApiResponses({
            @ApiResponse(code = ResponseState.not_support_operation_code, message = ResponseState.not_support_operation_message),
            @ApiResponse(code = ResponseState.failed_code, message = ResponseState.failed_message),
            @ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message),
    })
    @GetMapping
    public ResponseResult doSearch(@RequestParam("keyword") String keyword,
                                   @RequestParam("page") int page,
                                   @RequestParam("size") int size,
                                   @RequestParam(value = "categoryId", required = false) String categoryId,
                                   @RequestParam(value = "sort", required = false) Integer sort) {

        return solrService.doSearch(keyword, page, size, categoryId, sort);
    }
}
